package com.zx.controller;


import com.zx.bean.Worker;
import com.zx.dto.AjaxJson;
import com.zx.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class WorkerController {
    @Autowired
    private WorkerService workerService;

    @PostMapping("/addWorker")
    public String addWorker(Worker worker){
        return "add";
    }

    //定义一个删除接口
    @PostMapping("/delWorker")
    public String delWorker(int id){
        workerService.delWorker(id);
        return "del";
    }

    //定义一个修改的接口
    @PostMapping("/updateWorker")
    public String updateWorker(int id){
        workerService.updateWorker(id);
        return "updateFirm";
    }

    //定义一个查询单个的接口
    @PostMapping("/findOneWorker")
    @ResponseBody
    public AjaxJson findOneWorker(int id){
        AjaxJson ajaxJson = new AjaxJson();
        Worker worker = workerService.findOneWorker(id);
        ajaxJson.put("worker",worker);
        return ajaxJson;
    }

    //定义一个查询全部的接口
    @PostMapping("/findAllWorker")
    @ResponseBody
    public AjaxJson findAllWorker(){
        AjaxJson ajaxJson = new AjaxJson();
        workerService.findAllWorker();
        return ajaxJson;
    }
}
